package offer;
//连续子数组的最大和
public class T31 {
    public int FindGreatestSumOfSubArray(int[] array) {
        int maxx = Integer.MIN_VALUE;
        int temp = 0;
        for (int i=0;i<array.length;i++) {
            temp+=array[i];
            if (temp<0) {
                temp = 0;
            }else maxx = maxx>temp?maxx:temp;
        }
        if (maxx==Integer.MIN_VALUE) {
            for (int i = 0; i < array.length; i++) {
                maxx =  maxx>array[i]?maxx:array[i];
            }
        }
        return maxx;
    }
}
